class TypeConverter:
    '''
    field类
    '''
    # 根据field类型转换var
    @staticmethod
    def str_to_field_var(s, t):
        from src.catalog.field import FieldType
        if s is None:
            return None
        if t == FieldType.INTEGER:
            return int(s)
        if t == FieldType.FLOAT:
            return float(s)
        if t == FieldType.BOOLEAN:
            return s.strip().lower() in ("1", "true", "t", "yes", "y")
        if t == FieldType.VARCHAR or t == FieldType.DATE:
            return str(s)
        return s

    @staticmethod
    def _normalize_field_type(field_type) :
        """将多种表示标准化为 FieldType

        将不同形式的类型表示（字符串、枚举等）转换为标准的FieldType枚举

        Args:
            field_type: 输入的字段类型表示

        Returns:
            标准化的FieldType枚举值

        Raises:
            ValueError: 当类型不受支持时抛出异常
        """
        from src.catalog.field import FieldType

        if isinstance(field_type, FieldType):
            return field_type
        if isinstance(field_type, str):
            s = field_type.strip().lower()
            if s in ("int", "int32", "int64", "integer"):
                return FieldType.INTEGER
            if s in ("varchar", "string", "text"):
                return FieldType.VARCHAR
            if s in ("float", "double", "real"):
                return FieldType.FLOAT
            if s in ("bool", "boolean"):
                return FieldType.BOOLEAN
            if s in ("date", "datetime", "timestamp"):
                return FieldType.DATE
        raise ValueError(f"Unsupported field type: {field_type}")

    '''
    table类
    '''

    #
    # def list_to_raw(self, xid: int, values: List[str]) -> None:
    #     """插入记录
    #
    #     将一组值插入表中作为新记录，并更新相关索引
    #
    #     Args:
    #         xid: 事务ID
    #         values: 字段值列表，顺序与表字段定义一致
    #
    #     Raises:
    #         ValueError: 当值的数量与字段数量不匹配时抛出异常
    #     """
    #     # 删除检查隐藏ID字段的代码
    #     # 不再处理隐藏ID字段
    #     # has_hidden_id = len(self.fields) > 0 and self.fields[0].name == "_id"
    #     # if has_hidden_id and len(values) == len(self.fields) - 1:
    #     #     next_id = self._get_next_id()
    #     #     values.insert(0, str(next_id))
    #
    #     if len(values) != len(self.fields):
    #         raise ValueError(f"Expected {len(self.fields)} values, got {len(values)}")
    #
    #     # 将字符串值转换为对应类型的字典
    #     entry = {}
    #     for i, field in enumerate(self.fields):
    #         # entry[field.name] = TypeConverter.str_to_field_var(values[i], field.field_type)
    #         entry[field.name] = field.serialize_value(values[i]